<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>待放款管理</title>
    <link rel="stylesheet" href="../../../static/layer/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../../../static/css/font-awesome.min.css" media="all">

</head>

<body>

<div style="padding: 20px; position: relative;">
    <div class="operateTable">
        <div class="layui-inline">
            <input class="layui-input" name="COMPANY_NAME"   id="COMPANY_NAME" placeholder="借款方名称" autocomplete="off">
        </div>

        <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
            <input type="text" class="layui-input" id="test1" placeholder="开始时间">
        </div> -
        <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
            <input type="text" class="layui-input" id="test2" placeholder="结束时间">
        </div>
        <button class="layui-btn" data-type="reload">搜索</button>
    </div>



    </div>

    <table class="layui-table" id='buildingTable' lay-filter="business">
    </table>

  <div id="barDemo"  style="display: none">
        <a class="layui-btn layui-btn-primary layui-btn-mini AUTH-CWQX_FK"  lay-event="btnOpen"  >确定放款</a>
    </div>

</div>

<script type="text/javascript" src="../../../static/layer/layui.js"></script>
<script type="text/javascript" src="../../../static/js/common/dateUtils.js"></script>
<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
<script>
    var table;
    var businessId = "";
    layui.use(['jquery', 'table', 'form', 'layer', 'element','laydate'], function () {
        table = layui.table;
        var  element = layui.element, //导航的hover效果、二级菜单等功能，需要依赖element模块
            form = layui.form,
            laydate = layui.laydate;

        laydate.render({
            elem: '#test1' //指定元素

        });

        laydate.render({
            elem: '#test2' //指定元素
        });
        $("#test1").val(DateUtils.firstDate());
        $("#test2").val(DateUtils.lastDate());

        var active = {
            reload: function () {
                var starTime = $('#test1').val();
                var endTime = $('#test2').val();
                var name = $('#COMPANY_NAME').val();
                reloadTable(name,starTime,endTime);
            },

        };




        active.reload();

        //监听工具条
        table.on('tool(business)', function (obj) {
            debugger
            var  data=obj.data;
            layer.confirm('确定要放款吗？', {
                btn: ['确定', '取消'] //按钮
            }, function (index) {
                layer.close(index);
                $.ajax({
                    url: "/financial/saveLoan",
                    data: {"ID":data.id},
                    dataType: "json",
                    type: "post",
                    async: false,
                    success: function (res) {
                        if (res.errcode === "0") {
                            window.location.href="./beOverdue.html";
                        } else if (res.errcode === "1") {
                            layer.msg(res.errmsg, function () {
                            });
                        }
                    }
                });
            }, function (index) {

            })


        });

            function reloadTable(name,starTime,endTime) {
            var data = {};
            if (!!name) {
                data.COMPANY_NAME = name;
            }
            if (!!starTime) {
                data.starTime = starTime;
            }
            if (!!endTime) {
                data.endTime = endTime;
            }
            table.render({
                elem: '#buildingTable',
                url: '/financial/beOverdueList/',
                page: true,
                limit: 20,
                height: 'full-150',
                where: data,
                cols: [[
                    {field: 'ROWNUM', fixed: true, width: 70}
                    , {field: 'COMPANY_NAME', title: '借款方名称', width: 250}
                    , {field: 'SIGNER', title: '签订人姓名', width: 150}
                    , {field: 'SIGNER_TEL', title: '签订人联系方式', width: 200}
                    , {field: 'TOTAL_PRICE', title: '应放款金额(元)', width: 200 , align: 'right'}
                    , {field: 'START_DATE', title: '应放款时间', width: 200 }
                    , {field: '', title: '账单周期', width: 200 ,toolbar: '#timeBE'}


                    , {fixed: 'right', title: '操作', width: 200, align: 'center', toolbar: '#barDemo'}

                ]]
            });
        }
        $('.operateTable .layui-btn').on('click', function () {
            debugger
            var type = $(this).data('type');
            // alert(type);
            active[type] ? active[type].call(this) : '';
        });


    });



</script>


<script type="text/javascript" src="../../../static/js/common/authUtils.js"></script>
<script id="timeBE" type="text/html">

    <div >
        {{d.START_DATE}}-  {{d.END_DATE}}
    </div>

</script>
</body>

</html>